package com.bank.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bank.code.RespCode;
import com.bank.dao.SubjectDao;
import com.bank.entity.Subject;
import com.bank.excption.CommonException;

@Service(value="subjectService")
public class SubjectServiceImpl implements SubjectService {

	@Autowired
	SubjectDao  subjectDao;
	
	public void save(Map<String, Object> params) throws CommonException {
		String subjectNumber = (String)params.get("subject_number");
		Subject subject =  subjectDao.get(subjectNumber);
		if(subject != null){
			throw new CommonException(RespCode.SUB_IS_EXIST, "科目已存在");
		}
		subject = new Subject();
		subject.setSubject_number(subjectNumber);
		subject.setSubject_name((String)params.get("subject_name"));
		subject.setSubject_balance_direct((String)params.get("subject_balance_direct"));
		subject.setSubject_type((String)params.get("subject_type"));
		subject.setSubject_level((String)params.get("subject_level"));
		subject.setSuper_subject((String)params.get("super_subject"));
		subject.setSubject_status("1");
		subjectDao.save(subject);
	}

	public void update(Map<String, Object> parmas) throws CommonException {
		String subjectNumber = (String)parmas.get("subject_number");
		Subject subject =  subjectDao.get(subjectNumber);
		if(subject == null){
			throw new CommonException(RespCode.SUB_NOT_EXIST, "科目不存在");
		}
		subject.setSubject_name((String)parmas.get("subject_name"));
		subject.setSubject_balance_direct((String)parmas.get("subject_balance_direct"));
		subject.setSubject_type((String)parmas.get("subject_type"));
		subject.setSubject_level((String)parmas.get("subject_level"));
		subject.setSuper_subject((String)parmas.get("super_subject"));
		subject.setSubject_status("1");
		subjectDao.update(subject);
	}

	public Subject get(Map<String, Object> parmas) {
		return subjectDao.get((String)parmas.get("subject_number"));
	}

	public List<Object> getSubjectList(Map<String, Object> param) {
		return subjectDao.getSubjecList(param);
	}

	public Integer getSubjectListCount(Map<String, Object> param) {
		return subjectDao.getSubjectListCount(param);
	}

}
